






function submitComment(){
    let orderId = $('#order-id').html();
    let comment = $('#comment-textarea').val();
    console.log('orderId'+orderId+'comment'+comment);
    let star = $("input[name='score']").val();
    console.log('star'+star);

    $.ajax({
        type    :   'POST',
        url     :   _common_util.getServerURL('order/order_review'),
        dataType : 'json',
        data    :    {
            'orderId' : orderId,
            'comment' : comment,
            'star'      : star
        },
        success : function (res) {
            if (res.status === 0 ){
                window.wxc.xcConfirm('完成评价','success',{onOk:function () {
                        // location.reload();
                    }});
            }
        }
    })
}


function showCommentField(){
    $('#comment-field').css('display','block');
}

$(function () {
    let orderId = _common_util.getURLParam('orderId');

    let flag =_common_util.getURLParam('commentflag');

    $('#comment-field').css('display','none');

    if(flag == 1){
        $('#comment-field').css('display','block');
    }


    $.ajax({
        type:'GET',
        url : _common_util.getServerURL('order/customer_order_detail?orderId=')+orderId,
        success:function (res) {
            console.log(res);
            if (res.status === 0){

                $('#order-id-top').html(res.data.orderId);
                $('#order-id').html(res.data.orderId);
                $('#order-date-top').html(res.data.createTime);
                $('#order-data').html(res.data.createTime);
                let name = '<a href="single-product.html?itemId='+res.data.itemId+'">'+res.data.itemName+'</a> ';
                $('#product-name').html( name);
                $('#product-count').html(res.data.itemNumber);
                $('#product-price').html(res.data.unitPrice);
                $('#order-price').html(res.data.totalPrice);

                let receiveaddress = "yaoyao" + res.data.cphone +" " +res.data.caddress;

                $('#receive-info').html(receiveaddress);
                $('#seller-phone').html(res.data.mphone);
                $('#seller-address').html(res.data.maddress);
                $('#product-description').html(res.data.caddress);


                let  imgsrc = _common_util.getImageUrl(res.data.img);

                $('#product-img').attr('src',imgsrc);

                let  oState= res.data.orderState;
                let oStateStr = '';
                if (oState === 0 ){
                    //未支付
                    oStateStr = ' <a href="###" style="margin-top: 10px" >未支付</a>\n' +
                        '      <a href="order.html?orderId='+res.data.orderId+'" style="margin-top: 10px" class="btn-info" >前往支付</a>'
                }else if (oState === 1){
                    //订单取消
                    oStateStr = ' <a href="###" style="margin-top: 10px" >订单已取消</a>\n'
                }else if (oState === 2){
                    //已支付待收货
                    oStateStr = ' <a href="###" style="margin-top: 10px" >已支付</a>\n'
                }else if (oState === 3){
                    //已收货待评价
                    oStateStr = ' <a href="###" style="margin-top: 10px" >已收货</a>\n' +
                        '      <a href="#" onclick="showCommentField()" style="margin-top: 10px" class="btn-info" >追加评论</a>'
                }else if (oState === 4){
                    oStateStr = ' <a href="###" style="margin-top: 10px" >已收货</a>\n' +
                        '      <a href="###"  style="margin-top: 10px" class="btn-info" >已评价</a>'
                }

                $('#order-state').html(oStateStr);
            }
        }

    })
})